package edu.njfu.intentdemo

import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        val button=findViewById<Button>(R.id.button)
//        button.setOnClickListener {
//            var intent = Intent(this,SecondActivity::class.java);
//            intent.putExtra("name","张三")
//            intent.putExtra("password","123456")
//            startActivityForResult(intent,1);
//        }
//        val button12=findViewById<Button>(R.id.button12);
//        button12.setOnClickListener {
//            val intent=Intent(this,ThirdActivity::class.java)
//            startActivity(intent)
//        }
//         val button12=findViewById<Button>(R.id.button12);
//         button12.setOnClickListener {
//
//         }
        button12.setOnClickListener {
            /**
             * Intent ,第一个参数，当前context，第二参数，表示要跳转的activity
             */
            val intent=Intent(this,SecondActivity::class.java)
            startActivity(intent)
        }

    }

//    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
//        super.onActivityResult(requestCode, resultCode, data)
//        when(requestCode){
//            1 -> if(resultCode== Activity.RESULT_OK){
//                val returnedData=data?.getStringExtra("msg")
//                Log.d("MainActivity",returnedData.toString())
//                var builder = AlertDialog.Builder(this)
//                builder.setTitle("第2个Activity返回值")
//                builder.setIcon(R.drawable.ic_launcher_background)
//                builder.setMessage(returnedData.toString())
//                builder.setCancelable(true);
//                //正面的按钮（肯定）
//                builder.setPositiveButton(
//                    "确定"
//                ) { dialog, which ->
//                    Toast.makeText(this@MainActivity, "OK", Toast.LENGTH_SHORT).show()
//                    dialog.cancel()
//                }
//                //反面的按钮（否定）
//                builder.setNegativeButton(
//                    "取消"
//                ) { dialog, which ->
//                    Toast.makeText(this@MainActivity, "取消", Toast.LENGTH_SHORT).show()
//                    dialog.cancel()
//                }
//
//                builder.show();
//            }
//        }
//    }
}
